package 剑指offer.demo5;
//https://www.nowcoder.com/practice/b6edb5ca15d34b1eb42e4725a3c68eba?
/*
很简单没啥考点就是比较麻烦的一到普通题，多注意观察就好了
 */
import java.util.Scanner;

public class 回文数索引 {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int T = scn.nextInt();
        while (T > 0) {
            String str = scn.next();
            if (isPalindrome(str, 0, str.length())) {
                System.out.println(-1);
            } else {
                for (int i = 0; i < str.length(); i++) {
                    StringBuffer stringBuffer = new StringBuffer(str);
                    if (isPalindrome(stringBuffer.deleteCharAt(i).toString(), 0, stringBuffer.length())) {
                        System.out.println(i);
                        break;
                    }
                }
            }
            T--;
        }

    }

    //构建辅助方法判断字符串在固定区间是不是回文
    public static boolean isPalindrome(String str, int start, int end) {
        int m = start;
        int n = end;
        for (int i = m; i < n / 2; i++) {
            if (str.charAt(i) != str.charAt(end - start - 1 - i))
                return false;
        }
        return true;
    }
}
